package com.zhj.interview;

import java.util.HashSet;
import java.util.Set;

/**
 * 查找字符串中AAB类型的数量，重复的忽略
 */
public class Test17 {

    public static void main(String[] args) {
        String str = "好好学习，好好学习，天天向上";
        System.out.println(findAabNum(str));
    }

    public static int findAabNum(String str) {
        if (str == null || "".equals(str)) {
            return 0;
        }
        Set<String> set = new HashSet<>();
        for (int i = 0; i < str.length(); i++) {
            Character cur = str.charAt(i);
            // 窗口
            if (str.length() - i > 2 && cur.equals(str.charAt(i+1)) && !cur.equals(str.charAt(i+2))) {
                String aab = cur.toString() + str.charAt(i+1) + str.charAt(i+2);
                set.add(aab);
            }
        }
        return set.size();
    }
}
